package com.hontech.kaltaapp.ui.parts

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Button
import android.widget.FrameLayout
import com.hontech.kaltaapp.R
import com.hontech.kaltaapp.device.CleanInfo
import com.hontech.kaltaapp.device.CookingInfo
import com.hontech.kaltaapp.device.cooking
import com.hontech.kaltaapp.ui.dialog.runProg
import com.hontech.kaltaapp.ui.view.LabelInput
import com.hontech.kaltaapp.utils.onClick

class CookingParts (context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val liKpa: LabelInput
    private val liC: LabelInput
    private val liWater: LabelInput
    private val liD: LabelInput
    private val liSteam: LabelInput

    private val liK: LabelInput
    private val liPreWater: LabelInput
    private val liF: LabelInput
    private val liG: LabelInput
    private val liDefroze: LabelInput
    private val liE: LabelInput
    private val liPourWater: LabelInput
    private val liH: LabelInput
    private val liMixsoup: LabelInput
    private val liI: LabelInput
    private val liClogging: LabelInput


    init {
        val view = LayoutInflater.from(context).inflate(R.layout.parts_cooking, this)
        liKpa = view.findViewById(R.id.id_cooking_kpa)
        liC = view.findViewById(R.id.id_cooking_c)
        liWater = view.findViewById(R.id.id_cooking_water)
        liD = view.findViewById(R.id.id_cooking_d)
        liSteam = view.findViewById(R.id.id_cooking_steam)

        liK = view.findViewById(R.id.id_cooking_k)
        liPreWater = view.findViewById(R.id.id_cooking_pre_water)
        liF = view.findViewById(R.id.id_cooking_f)
        liG = view.findViewById(R.id.id_cooking_g)
        liDefroze = view.findViewById(R.id.id_cooking_defroze)
        liE = view.findViewById(R.id.id_cooking_e)
        liPourWater = view.findViewById(R.id.id_cooking_pour_water)
        liH = view.findViewById(R.id.id_cooking_h)
        liMixsoup = view.findViewById(R.id.id_cooking_mixsoup)
        liI = view.findViewById(R.id.id_cooking_i)
        liClogging = view.findViewById(R.id.id_cooking_clogging)

        val btn = view.findViewById<Button>(R.id.id_cooking_btn_cooking)
        btn.onClick { onClickCooking() }
    }

    private suspend fun onClickCooking() {
        runProg("煮面", "煮面") {

            val clean = CleanInfo(
                liKpa.textInt(),
                liC.textInt(),
                liD.textInt(),
                liWater.textInt(),
                liSteam.textInt()
            )
            val cooking = CookingInfo(
                liK.textInt(),
                liPreWater.textInt(),
                liF.textInt(),
                liG.textInt(),
                liDefroze.textInt(),
                liE.textInt(),
                liPourWater.textInt(),
                liH.textInt(),
                liMixsoup.textInt(),
                liI.textInt(),
                liClogging.textInt()
            )

            cooking(clean, cooking, it)
        }
    }
}




















